//
//  LoginWayView.swift
//  swiftProject
//
//  Created by ZhangSai on 2021/4/25.
//

import UIKit

class LoginWayView: UIView {

    typealias LoginWayViewBlock = (Int) -> Void
    var loginWayViewBlock : LoginWayViewBlock!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(self.nextBtn)
        self.addSubview(self.passWordLogin)
        self.addSubview(self.faceBookLogin)
        self.addSubview(self.appleLogin)

        self.nextBtn.snp.makeConstraints { (make) in
            make.top.equalTo(self.snp.top).offset(0)
            make.left.equalTo(self.snp.left).offset(0)
            make.right.equalTo(self.snp.right).offset(0)
            make.height.equalTo(45)
        }
        self.passWordLogin.snp.makeConstraints { (make) in
            make.top.equalTo(self.nextBtn.snp.bottom).offset(10)
            make.left.equalTo(self.snp.left).offset(0)
            make.height.equalTo(30)
            let title:String =  ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_passLogin)
            make.width.equalTo(title.getWidth(UIFont.systemFont(ofSize: 13))+15)
        }
        self.faceBookLogin.snp.makeConstraints { (make) in
            make.top.equalTo(self.nextBtn.snp.bottom).offset(10)
            make.right.equalTo(self.snp.right).offset(0)
            make.height.equalTo(30)
            make.width.equalTo(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_loginFB).getWidth(UIFont.systemFont(ofSize: 13))+15)
        }
        self.appleLogin.snp.makeConstraints { (make) in
            make.top.equalTo(self.faceBookLogin.snp.bottom).offset(10)
            make.right.equalTo(self.snp.right).offset(0)
            make.left.equalTo(self.snp.left).offset(0)
            make.height.equalTo(35)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func refreshUI(index:Int) {
        self.faceBookLogin.setTitle(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_loginFB), for: .normal)
        self.appleLogin.setTitle(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.loginAppleID), for: .normal)
        self.nextBtn.setTitle(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_next), for: .normal)
        self.passWordLogin.setTitle(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_passLogin), for: .normal)
        self.passWordLogin.snp.updateConstraints { (make) in
            let title:String =  ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_passLogin)
            make.width.equalTo(title.getWidth(UIFont.systemFont(ofSize: 13))+15)
        }
    }
    
    @objc func loginWay(sender:UIButton) {
        if loginWayViewBlock != nil {
            if sender == passWordLogin {
                loginWayViewBlock(1)
            } else if sender == faceBookLogin {
                loginWayViewBlock(2)
            } else if sender == appleLogin {
                loginWayViewBlock(3)
            }
        }
    }
    @objc func clickNextBtn() {
        if (loginWayViewBlock != nil) {
            loginWayViewBlock(4)
        }
    }
    
    lazy var nextBtn:UIButton = {
        let nextBtn = UIButton()
        nextBtn.setTitle(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_next), for: .normal)
        nextBtn.backgroundColor = UIColor.init(hexString: "#FFD10A")
        nextBtn.setTitleColor(UIColor.init(hexString: "#333333"), for: .normal)
        nextBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18)
        nextBtn.layer.cornerRadius = 5
        nextBtn.addTarget(self, action: #selector(clickNextBtn), for: .touchUpInside)
        return nextBtn
    }()
    
    lazy var passWordLogin:UIButton = {
        let passWordLogin = UIButton()
        passWordLogin.setTitle(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_passLogin), for: .normal)
        passWordLogin.setTitleColor(UIColor.init(hexString: "#424242"), for: .normal)
        passWordLogin.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        passWordLogin.setImage(UIImage.init(named: "login_passWord"), for: .normal)
        passWordLogin.addTarget(self, action: #selector(loginWay), for: .touchUpInside)
        return passWordLogin
    }()
    
    lazy var faceBookLogin:UIButton = {
        let faceBookLogin = UIButton()
        faceBookLogin.setTitle(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_loginFB), for: .normal)
        faceBookLogin.setTitleColor(UIColor.init(hexString: "#424242"), for: .normal)
        faceBookLogin.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        faceBookLogin.setImage(UIImage.init(named: "login_facebook"), for: .normal)
        faceBookLogin.addTarget(self, action: #selector(loginWay), for: .touchUpInside)
        return faceBookLogin
    }()
    
    lazy var appleLogin:UIButton = {
        let appleLogin = UIButton()
        appleLogin.setTitle(ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.loginAppleID), for: .normal)
        appleLogin.setTitleColor(UIColor.init(hexString: "#424242"), for: .normal)
        appleLogin.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        appleLogin.layer.cornerRadius = 2.5;
        appleLogin.layer.borderWidth = 0.5;
        appleLogin.layer.borderColor = UIColor.black.cgColor;
        appleLogin.setImage(UIImage.init(named: "login_appleID"), for: .normal)
        appleLogin.addTarget(self, action: #selector(loginWay), for: .touchUpInside)
        return appleLogin
    }()
}
